@extends('layouts.app')
@section('title','添加服务')
@section('content')
<!-- start: Content -->
<div class="row-fluid">
	<div class="box span12">
		<div class="box-header">
			<h2><i class="icon-edit"></i>添加服务详情</h2>
		</div>
		<div class="box-content">
			<form action="{{ URL('app/banner',$banner->id) }}" method='POST'  enctype="multipart/form-data" class="form-horizontal" style='height:3000px;'>
				{{ csrf_field() }}
				{{ method_field('PUT') }}
			  <fieldset>
				<div class="control-group">
				  <label class="control-label" for="typeahead">轮播图链接:</label>
				  <div class="controls">
					<select name='href' class="form-control">
						@foreach($serve as $sv)
							@if($banner->href == URL('serve/details',$sv->id))
								<option value='{{ $sv->id }}' selected = "selected">{{ $sv->title }}</option>
							@else
								<option value='{{ $sv->id }}'>{{ $sv->title }}</option>
							@endif
						@endforeach
					</select>
					<p class="help-block" style='color:red;'>选择轮播图链接!</p>
				  </div>
				</div>
				<div class="control-group hidden-phone">
				  <label class="control-label" for="textarea2">轮播图文本:</label>
				  <div class="controls">
					<textarea style='width:665px;height:65px;' name='commit'  rows="3" maxlength="50">{{ $banner->commit }}</textarea>
					<p class="help-block" style='color:red;'>轮播图文本最多可以输入50字!</p>
				  </div>
				</div>
				<div class="control-group">
				  <label class="control-label" for="fileInput">轮播图</label>
				  <div class="controls">
				  	<div style='float:left;' id="localImag">
				  		<img id="preview" src="{{ $banner->path }}" width="150" height="180" style="display: block; width: 150px; height: 180px;" >
				  	</div>
        			<input type="file" name="fileimg"  id="doc" style="width:150px;" onchange="javascript:setImagePreview();">
					<p class="help-block" style='color:red;'>注：图片比例为1：0.43，图片尺寸为0、750*320，1500*740（参考），可为JPG，PNG</p>
				  </div>
				</div> 
				<div class="form-actions">
				  <button type="submit" class="btn btn-primary">确定</button>
				</div>
			  </fieldset>
			</form>   
		</div>
	</div><!--/span-->
</div><!--/row-->
<!-- end: Content -->
@stop
<script type="text/javascript">


  function setImagePreview(avalue) {
                var docObj = document.getElementById("doc");
                var imgObjPreview = document.getElementById("preview");
                if(docObj.files && docObj.files[0])
                {
                    //火狐下，直接设img属性
                    imgObjPreview.style.display = 'block';
                    imgObjPreview.style.width = '150px';
                    imgObjPreview.style.height = '180px';
                    //imgObjPreview.src = docObj.files[0].getAsDataURL();
                    //火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式
                    imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
                }
                else
                {
                    //IE下，使用滤镜
                    docObj.select();
                    var imgSrc = document.selection.createRange().text;
                    var localImagId = document.getElementById("localImag"); //必须设置初始大小
                    localImagId.style.width = "150px";
                    localImagId.style.height = "180px"; //图片异常的捕捉，防止用户修改后缀来伪造图片
                    try {
                        localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
                        localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
                    } catch(e) {
                        alert("您上传的图片格式不正确，请重新选择!");
                        return false;
                    }
                    imgObjPreview.style.display = 'none';
                    document.selection.empty();
                }
                return true;
            }
</script>